package com.woniuxy.order.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.core.util.JwtUtil;
import com.woniuxy.core.util.Result;
import com.woniuxy.order.dto.CommentDto;
import com.woniuxy.order.form.CommentInsertForm;
import com.woniuxy.order.param.CommentInsertParam;
import com.woniuxy.order.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  评论表 前端控制器
 * </p>
 *
 * @author ...
 * @since 2024年05月22日
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论相关接口")
public class CommentController {


    @Resource
    private CommentService commentService;

    /**
     * 评价成功
     * @param form
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation("评价操作")
    @ApiImplicitParams({@ApiImplicitParam(name = "form",value = "评价内容"),
    @ApiImplicitParam(name = "token",value = "用户登录ID")
    })
    public Result insert(@RequestBody CommentInsertForm form, @RequestHeader String token) throws Exception {
        Integer userId = (Integer) JwtUtil.getData(token, "id");
        commentService.insert(BeanUtil.toBean(form, CommentInsertParam.class),userId);
        return Result.success("评价成功",null);
    }

    /**
     * 查看评价成功
     * @param orderNum
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看评价")
    @ApiImplicitParam(name = "orderNum",value = "订单编号")
    public Result list(String orderNum) throws Exception {
        List<CommentDto> dtos =  commentService.commentList(orderNum);
        return Result.success("查询订单评价成功",dtos);
    }

}

